[ Home | Prev | Next ]

Chapter 2: continued


Variables, the Object Database, and Tables

All the examples so far have simply carried out computations and displayed their values in the Quick Script window. You can also store values in variables so they can be used later. Figure 2-10 shows an example of a script that places a string into a variable named examples.greeting.


Figure 2-10. Sample Variable Assignment

We can then use the new variable in another Frontier script, as you can see from Figure 2-11.


Figure 2-11. Use of a Sample Variable

That's how you store values in variables. Notice that the "category.name" format can be used for variables as well as verbs. Variable values are stored permanently in Frontier's Object Database. In this case, Frontier created (or updated) a variable named "greeting" in a table named "examples". Next time you start Frontier there will be a variable named examples.greeting and its value will be "Hello World!" (You can also create temporary variables that will not be stored; that's covered in Chapter 3.)

You can easily browse through all the stored values and change them interactively by opening the Object Database. There are two ways to do this:

In either case, you will see the Object Database table open into a window that looks something like Figure 2-12.


Figure 2-12. Top Level of Object Database

This table is the place where all variables and values are stored. You may think "Object Database" is too-fancy a name for what's going on here. But stay with it; you'll see soon why it's a database that stores objects.

Click on the triangle to the left of "examples" so that it is highlighted as shown in the figure. (It's also ok to just have the cursor in the examples "cell".) Click the Zoom button on the right side of the window; it will zoom open the examples table. The window that opens should look something like Figure 2-13, although it may be a different size and may be scrolled to a different position. If it helps, resize the window using the standard Macintosh resize box in the lower right corner.


Figure 2-13. Inside the Examples Table

This is where examples.greeting is stored. The table is named examples and the entry is called greeting. To prove this, change the value in the Quick Script window by typing the script shown in Figure 2-14 and executing it.


Figure 2-14. A New Value for examples.greeting

As you can see (Figure 2-15), the value of the variable examples.greeting was changed by the script you just ran from the Quick Script window.


Figure 2-15. Variable Value Modified

There are a number of ways you can create variables. You will probably create them most often either from a UserTalk script or interactively in a table editor.

Try typing "examples.x = 12" (without the quotation marks, of course) in the Quick Script window. Note that there's a new value in the examples table called "x" and that it has a value of 12.

Creating a new variable interactively is a lot like adding information to a spreadsheet. Position the cursor anywhere in the table where you wish to store the new variable. Hold down the Command key and press Return. This opens a new entry in the table. Type the variable's name (e.g. "y") in the Name column. Tab to the Value column and enter a value (e.g. "27") for the variable, then hit the Enter key. You've created a new entry in the table.

There are other ways of creating new table entries and assigning them both a kind and a value. We'll discuss this subject in more detail in Chapters 4 and 5.

Frontier offers two different ways of editing the contents of objects in the Object Database. Some objects are edited "in place" in the table. You can tell these items because the item marker before their name is gray rather than a continuously outlined triangular shape. If the mouse cursor becomes an I-beam when you move it over the Value column of a variable, this is another indication you are dealing with a variable that can be edited directly in the table window. Only the simplest types of information (such as numbers and strings) can be edited in the table directly.

All other objects can only be edited in their own windows. Clicking the Zoom button or double-clicking on the item marker to the left of the entry's name in the table will open its editing window.

The Object Database can store many different types of data. To see all the different types supported by Frontier, press and hold the mouse on the "Kind" popup in the lower left corner of a table-editing window. An object can be as small as a number or a string, or as large as a script, word processing document or outline.

Some types can be converted to other types. In the examples table, look at the value of a variable called "green." Note that it is a number. Click on the item marker next to green and select "String" from the "Kind" popup. Notice that green is now a string of length 2 (that's what string [2] means). Convert it back to a number by selecting "Number" from the "Kind" popup.

You can resize the window the usual way. Frontier remembers the size and positions of all its windows from one session to the next (assuming that you save the root file).

You can change the widths of columns in a table editor. Carefully move the mouse over the border lines between columns. When the cursor changes to a pair of vertical "rails" with small left & right arrows, press the mouse button down and drag the border line. Let up on the mouse whenever you like. The other two columns automatically resize to fill the remaining space.

Tables can contain sub-tables, and sub-sub-tables and so on, up to 25 levels deep. To refer to something that's nested in a table, put a dot between the name and its table's name, as in examples.greeting. The name examples.subTable1.message refers to an object named "message" in the sub-table called subTable1, which in turn is stored in the examples table.

Note, too, that when a table is open as the frontmost window in Frontier, a special menu called (logically enough) "Table" appears on the menubar. This menu contains many commands that you'll find useful in working with tables. Its commands are actually scripts written in UserTalk, so you can modify its behavior if you're adventuresome. The menu's basic usage is discussed in Chapter 7; we'll talk about menubars and their scripts later in this chapter.

Contents Page | Previous Section | Next Section -- Word Processing Windows


HTML formatting by Steven Noreyko January 1996, User Guide revised by UserLand June 1996